package com.bw.order_module.bind;

import android.view.LayoutInflater;
import android.view.View;

import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bw.order_module.R;
import com.bw.order_module.confirm.ConfirmAdapter;
import com.bw.order_module.entity.Order;
import com.bw.order_module.entity.OrderGoods;

import java.util.List;

public class ConfirmBind {

    @BindingAdapter(value = {"orderGoods"})
    public static void bindConfirm(RecyclerView recyclerView,
                                   List<OrderGoods>goods){
        ConfirmAdapter adapter = (ConfirmAdapter) recyclerView.getAdapter();
        if (adapter == null){
            adapter = new ConfirmAdapter();
            View head = LayoutInflater.from(recyclerView.getContext()).
                    inflate(R.layout.view_confirm_foot,null,false);
            adapter.addHeaderView(head);
            LinearLayoutManager manager = new LinearLayoutManager(recyclerView.getContext());
            manager.setOrientation(LinearLayoutManager.VERTICAL);
            recyclerView.setLayoutManager(manager);
            recyclerView.setAdapter(adapter);
        }else {
            adapter.setNewInstance(goods);
        }
    }

}
